<template>
    <div class="alert-event">
        <textarea :id="window.getRootName() + 'EVENT_MESSAGE'" :rows="4" placeholder="请输入要弹出的消息内容"></textarea>
    </div>
</template>

<script>
import bus from '@/js/event/bus.js';
import util from '@/js/util/util.js';
export default {
    props: {
        eventData: {
            type: Array,
            default: []
        }
    },
    data() {
        return {
            window: window
        };
    },
    mounted() {
        bus.on('getEventData', this.getEventData);
        this.$nextTick(() => {
            if (this.eventData.length > 0 && this.eventData[0].event === 'alert') {
                this.setEventData(this.eventData[0]);
            }
        });
    },
    destroyed() {
        bus.off('getEventData', this.getEventData);
    },
    methods: {
        getEventData() {
            let value = document.getElementById(window.getRootName() + 'EVENT_MESSAGE').value;
            if (util.isBlank(value)) {
                return {
                    error: true,
                    message: ['请输入要弹出的消息内容！']
                };
            } else {
                return value;
            }
        },
        setEventData(event) {
            document.getElementById(window.getRootName() + 'EVENT_MESSAGE').value = event.param;
        }
    }
};
</script>

<style lang="scss" scoped>
.alert-event {
    height: 100%;
}
</style>